<template>
	<!-- 登录 -->
	<view>

		<cxView padding="150rpx 50rpx 20rpx 50rpx">

			<cxView display="flex" flexDirection="column" justify-content="center" align-items="center">
				<cxImg width="120" height="120" size="120" src="/static/logo.png"></cxImg>
				<cxView color="#333" fontWeight="600" size="30" marginTop="20">
					欢迎来到维修管理平台
				</cxView>
			</cxView>
			<cxView marginTop="50">
				<cxFormInput placeholder="请输入登录帐号" v-model="model.username" type="text" margin="50 20 0 20"
					background="white" :showCircula="true" padding="20 30"></cxFormInput>

				<cxFormInput placeholder="请输入密码" v-model="model.password" type="password" margin="50 20 0 20"
					background="white" :showCircula="true" padding="20 30">

					<cxButton background="transparent" slot="right" @confirm="forgetClick"
						:color="$cx.color.cxMainColor" mini>忘记密码</cxButton>

				</cxFormInput>

				<cxButton @confirm="login" height="100" :background='$cx.color.cxMainColor' color="white"
					:showCircula="true" marginTop="100">登录</cxButton>


				<!-- <cxView display="flex" alignItems="center" justifyContent="center" padding="20 20">
					<cxCheckBox :checked="check" active-color="#f70" name="勾选代表同意" @confirm="checkboxChange">
					</cxCheckBox>
					<cxView :color="$cx.color.cxMainColor" @confirm="getAgreement(0)">用户协议</cxView>和
					<cxView :color="$cx.color.cxMainColor" @confirm="getAgreement(1)">隐私协议</cxView>
				</cxView> -->
			</cxView>
		</cxView>

		</cxView>


	</view>
</template>

<script>
	import _enum from '@/common/enum'
	export default {
		data() {
			return {
				current: 0,
				tabList: [],
				check: false,
				bottom: uni.$cx.cxBottomSafeHeight() + 60,
				model: {
					username: '',
					password: '',
				},
				loginLogo: this.$baseUrl + '/profile/upload/static/phone_login.png', //手机号登录
				code: '',
				isPwdLogin: true,
				codeTips: '',
			}
		},

		onLoad() {
			// this.$log("color----",this.$cx.color.cxMainColor)
		},
		onReady() {

		},
		methods: {
			async login() {

				let status = this.validate()
				if (!status) {
					return
				}

				let result = await this.$login(this.model);
				if (result.code == 200) {

					uni.switchTab({
						url: "/pages/processing/processing"
					})

				}




			},

			/**
			 * 忘记密码
			 */
			forgetClick() {
				uni.$u.route({
					url: "/pages/login/resetPwd",
					params: {}
				})

			},


			checkboxChange(e) {

				this.check = !this.check;
				// this.check = e;

				// console.log(this.check)
			},
			// 数据校验
			validate() {
				let loginRules = [{
						name: 'username',
						required: true,

						errmsg: '请输入用户名'
					},
					{
						name: 'password',
						type: 'required',
						errmsg: '请输入密码'
					},

				]
				let result = uni.$cx.validate(this.model, loginRules);

				if (!result.isOk) {
					uni.showToast({
						icon: 'none',
						title: result.errmsg
					})
					return false
				} else {
					return true;
				}
			},

			getAgreement(index) {
				// console.log("------------")
				let param = {};
				if (index == 0) {
					// 用户协议
					param.key = "user_protocol"
				} else {
					// 用户隐私
					param.key = "user_privacy"
				}

				this.$u.api.getConfig(param).then(res => {
					if (res.code == 200) {
						let dic = {}
						if (index == 0) {
							// 用户协议
							dic.title = "用户协议"

						} else {
							// 用户隐私
							dic.title = "用户隐私"
						}
						dic.content = res.data;
						dic.type = 1;
						uni.$u.route({
							url: '/pages/public/webDetail/webDetail',
							params: dic
						})
					}
				})
			},
			// 返回
			navBack() {
				uni.switchTab({
					url: "/pages/index/index"
				})
			}




		},

	}
</script>
<!-- padding-top="150" marginLeft="50rpx" marginRight="50rpx" -->
<style lang="scss" scoped>
	.bgView {
		padding-top: 150rpx;
		margin: 0 50rpx;
	}
</style>